<%@ page import="com.dao.CateDao" %>
<%@ page import="java.util.List" %>
<%@ page import="com.beans.CateInfo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="css/edittable.css"/>
    <link rel="stylesheet" type="text/css" href="css/validate.css"/>
    <script type="text/javascript" src="js/jquery-1.8.0.js"></script>
    <script>
        $(function () {
            function validateCateName() {
                var result = true;
                var reg = /^\S{2,20}$/;   //2-20个合法字符(非空白)
                var cateName = $("#cateName").val();
                if (!reg.test(cateName)) {
                    result = false;
                    $("#cateName_msg").removeClass().addClass("validate_error").html("分类名称不合法");
                }
                if (result == true) {
                    $("#cateName_msg").removeClass().addClass("validate_ok").html("✓");
                }
                return result;
            }

            $("#cateName").blur(function () {
                validateCateName();
            });

            $("#form_btn").click(function () {
                var result = false;
                if (validateCateName() == true) {
                    result = true;
                }
                if (result == true) {
                    result = confirm("确认保存吗？");
                }
                return result;
            })
        })
    </script>

</head>
<body>
<%
    CateDao dao = new CateDao();
    Integer id = Integer.parseInt(request.getParameter("id"));
    CateInfo cateInfo = dao.getCateListById(id);
    request.setAttribute("cateInfo", cateInfo);
%>
<form method="post" action="CateServlet.do">
    <input type="hidden" value="updateBigCate" name="flag">
    <input name="id" value="${cateInfo.id}" type="hidden">
    <table class="edit_table">
        <tr>
            <td class="td_info">分类名称:</td>
            <td class="td_input_short">
                <input type="text" class="txtbox" id="cateName" name="cateName" value="${cateInfo.cateName}"/>
            </td>
            <td>
                <label class="validate_info" id="cateName_msg">长度 2-20 位非空白字符</label>
            </td>
        </tr>
        <tr>
            <td class="td_info">分类描述:</td>
            <td><textarea rows="4" cols="27" name="des" class="txtarea">${cateInfo.des}</textarea></td>
            <td><label></label></td>
        </tr>
        <tr>
            <td class="td_info"></td>
            <td>
                <input class="form_btn" id="form_btn" type="submit" value="保存修改"/>

            <td>
                <label id="result_msg" class="result_msg">${msg}</label>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
